package com.yyf.camera_product_plugin.ble;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yyf.camera_product_plugin.camera_product_plugin.R;

import java.util.List;

import cn.com.heaton.blelibrary.ble.model.BleDevice;

public class BlueListDialog extends Dialog {

    public static final int CONNECT_BLE = 100111;

    RecyclerView recyclerView;
    BlueListAdapter blueListAdapter;

    Activity activity;

    public BlueListDialog(@NonNull Activity context) {
        super(context);
        this.activity = context;
    }

    public void setDataList(List<BleDevice> bleDevices) {
        if (blueListAdapter == null) {
            blueListAdapter = new BlueListAdapter(getContext(), bleDevices);
            blueListAdapter.setOnItenClickListener(bleDevice -> {
//                ((ActivityAware) activity).connectBlue(bleDevice);
                dismiss();
            });
            recyclerView.setAdapter(blueListAdapter);
        } else {
            blueListAdapter.setDlist(bleDevices);
            blueListAdapter.notifyDataSetChanged();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_blue_list);
        setCanceledOnTouchOutside(false);

        recyclerView = findViewById(R.id.recycler);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(manager);
        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));

    }


}
